<!DOCTYPE html>
<html lang="en">
<head>
    {{include file="lib/page_head" /}}

    <style>
        table th{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        table td{word-wrap:break-word;word-break:break-all;font-size:12px!important;}
        .from_table .td_l,.from_table .td_r{font-size:14px!important;line-height: 25px;word-wrap:break-word;word-break:break-all}
        #search_form .form-control,#search_form .select5{width:160px;height:28px;padding:5px;}
        #search_form .layui-input-inline{width:auto;margin: 0;}
        #search_form .form-group{margin-right:0;margin-bottom: 5px;}
        #search_form .btn{height:30px;line-height:30px;padding:0 10px;}
        .layui-form-label{
            width:100px;
        }
        @media screen and (max-width: 640px)
        {
            #search_form .form-control,#search_form .select5{width:100%;}
        }
    </style>
</head>

<body>



<!-- Preloader -->
<div id="preloader">
    <div id="status"><i class="fa fa-spinner fa-spin"></i></div>
</div>

<section>
    {{include file="lib/page_left" /}}
    <div class="mainpanel">

        {{include file="lib/page_header" /}}

        <div class="contentpanel" >
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">×</a>
                        <a href="" class="minimize">−</a>
                    </div>
                    <h4 class="panel-title">订单列表</h4>
                </div>
                <div class="panel-body ">
                    <div id="search_list"  class="form-inline">
                        <div class="btn-group">
                            <button class="btn btn-primary" onclick="add_card()">添加新卡订单</button>
                            <button class="btn btn-primary" onclick="add_recharge()">添加充值订单</button>
                            <!--<button class="btn btn-primary" onclick="del_info(0)">删除</button>-->
                            <!--<button class="btn btn-primary" onclick="set_cancel(0)">取消</button>-->
                            <button class="btn btn-primary" onclick="location.href = location.href;">刷新</button>
                            <button class="btn btn-primary" onclick="export_csv()">导出</button>
                        </div>
                        <div class="layui-form-item search_tools" style="margin-top:10px;" >
                            <form class="layui-form" id="search_form" action="" onsubmit="return false;">
                                <div class="form-group">
                                    <input class="form-control" name="order_no"  autocomplete="off" type="text" placeholder="订单号">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" name="third_no"  autocomplete="off" type="text" placeholder="第三方交易号">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" name="card_no"  autocomplete="off" type="text" placeholder="加油卡号">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" name="user_mobile"  autocomplete="off" type="text" placeholder="用户手机号">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" name="mobile"  autocomplete="off" type="text" placeholder="收货人手机号">
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="agent_id" data-search="true">
                                        <option value="">请选择代理人</option>
                                        {{foreach $agent_list as $val }}
                                        <option value="{{$val.id}}">{{$val.agent_name}}</option>
                                        {{/foreach}}
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="supply_code" data-search="true">
                                        <option value="">请选择上游</option>
                                        {{foreach $supply_list as $val }}
                                        <option value="{{$val.supply_code}}">{{$val.supply_name}}</option>
                                        {{/foreach}}
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="mode">
                                        <option value="-1">请选择充值类型</option>
                                        <option value="0">充值</option>
                                        <option value="1">开卡</option>
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="card_type">
                                        <option value="-1">请选择卡类型</option>
                                        <option value="0">中石化普通卡</option>
                                        <option value="1" >中石化专属卡</option>
                                        <option value="2">中石化柴油专属卡</option>
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="pay_type">
                                        <option value="-1">请选择付款方式</option>
                                        <option value="0">手工付款</option>
                                        <option value="1">微信付款</option>
                                        <option value="2">支付宝付款</option>
                                        <option value="3">预存款</option>
                                        <option value="4">代理预存款</option>
                                        <option value="5">企业预存款</option>
                                        <option value="6">测试款</option>
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="pay_status">
                                        <option value="-1">请选择付款状态</option>
                                        <option value="0">未付款</option>
                                        <option value="1">已付款</option>
                                        <option value="2">付款失败</option>
                                        <option value="3">已退款</option>
                                        <option value="4">已取消</option>
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="status">
                                        <option value="-1">请选择订单状态</option>
                                        <option value="0">未处理</option>
                                        <option value="1">充值中</option>
                                        <option value="2">充值成功</option>
                                        <option value="3">充值失败</option>
                                    </select>
                                </div>
                                <div  class="form-group">
                                    <select class="select5" name="delivery_status">
                                        <option value="-1">请选择发货状态</option>
                                        <option value="0">不用发货</option>
                                        <option value="1">未发货</option>
                                        <option value="2">发货中</option>
                                        <option value="3">发货完成</option>
                                    </select>
                                </div>

                                <div  class="form-group">
                                    <select class="select5" name="is_rebate">
                                        <option value="-1">请选择是否返佣</option>
                                        <option value="0">未返</option>
                                        <option value="1">已返</option>
                                    </select>
                                </div>

                                <div class="form-group">
                                <input class="form-control" placeholder="开始日" name="date_1" id="date_1"  autocomplete="off">
                                <input class="form-control" placeholder="截止日" name="date_2" id="date_2" autocomplete="off">
                                </div>
                                <!--<div class="form-group">-->
                                    <!--<input class="form-control" id="search_date" autocomplete="off" placeholder="请选择日期范围" data-startDate="" data-endDate="" type="text">-->
                                <!--</div>-->

                                <div style="display: inline-block;clear: both;">
                                    <button class="btn btn-primary" onclick="search()">查询</button>
                                    <button class="btn btn-default" onclick="search_reset()">取消</button>
                                </div>
                            </form>

                            <div class="well well-sm search_toogle"><span class="glyphicon glyphicon-chevron-down"></span></div>
                            <div>售价：<span id="count_total_money">0.00</span>
                                成本：<span id="count_cost">0.00</span>
                                总卡费：<span id="count_card_fee">0.00</span>
                                代理佣金：<span id="count_agent_rebate">0.00</span>
                                利润：<span id="count_profit">0.00</span>
                                预存款充值：<span id="count_pay_supply_cost">0.00</span>
                                预存款消耗：<span id="count_supply_cost">0.00</span>
                            </div>
                        </div>
                    </div>
                    <div id="info_list" class="form-inline">

                    </div>
                </div>
            </div>
        </div><!-- contentpanel -->

    </div><!-- mainpanel -->
    {{include file="lib/page_right" /}}
</section>
<div id="add_card" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="order_id" value="0">

            <div  class="form-group">
                <label >用户</label>
                <select class="select5" name="user_id" data-ignore="true" data-search="true">
                    <option value="">请选择</option>
                    {{foreach $user_ids as $val }}
                    <option value="{{$val.id}}">{{$val.mobile}}</option>
                    {{/foreach}}
                </select>
            </div>
            <div  class="form-group">
                <label >代理人</label>
                <select class="select5" name="agent_id" data-search="true">
                    <option value="0">请选择</option>
                    {{foreach $agent_list as $val }}
                    <option value="{{$val.id}}">{{$val.agent_name}}</option>
                    {{/foreach}}
                </select>
            </div>
            <div  class="form-group">
                <label > 卡号<span style="color:red;">*</span></label>
                <select class="select5" name="card_no" data-search="true">
                    <option value="0">请选择</option>
                    {{foreach $card_list as $val }}
                    <option value="{{$val.card_no}}">{{$val.card_no}}</option>
                    {{/foreach}}
                </select>

            </div>
            <div  class="form-group">
                <label >套餐<span style="color:red;">*</span></label>
                <select class="select5" name="product_id">
                    <option value="0">请选择</option>
                    {{foreach $card_package_list as $val }}
                    {{if $val.mode == 1 }}
                    <option value="{{$val.id}}">{{$val.name}}</option>
                    {{/if}}
                    {{/foreach}}
                </select>
            </div>
            <div  class="form-group">
                <label > 运费</label>

                <input class="form-control" placeholder="运费" name="freight" type="number" value="" data-ignore="true">
            </div>
            <div  class="form-group">
                <label > 卡费</label>

                <input class="form-control" placeholder="卡费" name="card_fee" type="number" value="" data-ignore="true">
            </div>
            <div  class="form-group">
                <label > 优惠金额</label>
                <input class="form-control" placeholder="优惠金额" name="discount_money" type="number" value="" data-ignore="true">
            </div>
            <div  class="form-group">
                <label > 真实姓名<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="真实姓名" name="real_name" type="text" value="">
            </div>
            <div  class="form-group">
                <label > 手机号<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="手机号" name="mobile" type="text" value="">
            </div>
            <div  class="form-group">
                <label > 地址<span style="color:red;">*</span></label>
                <textarea class="form-control" placeholder="地址" name="address" ></textarea>
            </div>
        </form>
    </div>
</div>
<div id="add_new_card" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="order_id" value="0">
            <div  class="form-group">
                <label > 卡号</label>
                <select class="select5" name="card_no" data-search="true">
                    <option value="0">请选择</option>
                    {{foreach $card_list as $val }}
                    <option value="{{$val.card_no}}">{{$val.card_no}}</option>
                    {{/foreach}}
                </select>

            </div>

        </form>
    </div>
</div>

<div id="add_recharge" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="order_id" value="0">

            <div  class="form-group">
                <label >用户<span style="color:red;">*</span></label>
                <select class="select5" name="user_id" data-ignore="true" data-search="true" onchange="change_user_id(this)">
                    <option value="">请选择</option>
                    {{foreach $user_ids as $val }}
                    <option value="{{$val.id}}">{{$val.mobile}}</option>
                    {{/foreach}}
                </select>
            </div>

            <div  class="form-group">
                <label > 卡号<span style="color:red;">*</span></label>
                <select class="select5" name="card_no" data-search="true">
                    <option value="0">请选择</option>

                </select>

            </div>
            <div  class="form-group">
                <label >套餐<span style="color:red;">*</span></label>
                <select class="select5" name="product_id" data-search="true">
                    <option value="0">请选择</option>
                    {{foreach $card_package_list as $val }}
                    {{if $val.mode == 0 ||$val.mode == 2 }}
                    <option value="{{$val.id}}">{{$val.name}}</option>
                    {{/if}}
                    {{/foreach}}
                </select>
            </div>
            <div  class="form-group">
                <label > 优惠金额</label>
                <input class="form-control" placeholder="优惠金额" name="discount_money" type="number" value="" data-ignore="true">
            </div>

        </form>
    </div>
</div>



<div id="delivery" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="order_id" value="0">
            <div  class="form-group">
                <label > 代理</label>
                <input class="form-control" placeholder="代理" name="agent_id" type="text" value="" data-ignore="true" disabled>
            </div>
            <div  class="form-group">
                <label > 代理备注</label>
                <input class="form-control" placeholder="代理备注" name="agent_info" type="text" value="" data-ignore="true" style="color:red;font-weight: bold;" disabled >
            </div>

            <div  class="form-group">
                <label > 真实姓名<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="真实姓名" name="real_name" type="text" value="" disabled>
            </div>
            <div  class="form-group">
                <label > 联系方式<span style="color:red;">*</span></label>
                <input class="form-control" placeholder="联系方式" name="mobile" type="text" value="" disabled>
            </div>
            <div  class="form-group">
                <label > 地址<span style="color:red;">*</span></label>
                <textarea class="form-control" placeholder="地址" name="address" disabled ></textarea>
            </div>
            <div  class="form-group">
                <label > 快递名称</label>
                <input class="form-control" placeholder="快递名称" name="express_name"  type="text" value="" data-ignore="true">
            </div>
            <div  class="form-group">
                <label > 快递号&nbsp;&nbsp;<span id="express_no_text"></span></label>
                <input class="form-control" placeholder="快递号" name="express_no" type="text" value="" data-ignore="true">
            </div>
            <div  class="form-group">
                <label > 发货状态</label>
                <select class="select5" name="delivery_status">
                    <option value="0">不用发货</option>
                    <option value="1">备货</option>
                    <option value="2">发货中</option>
                    <option value="3">发货完成</option>

                </select>
            </div>
            <div  class="form-group">
                <label > 发货信息(<i id="delivery_list_state" style="color:red;">发货中</i>)</label>
                <ul class="layui-timeline" id="delivery_list">



                </ul>
            </div>


        </form>
    </div>
</div>



<div id="refund_fee" style="display: none;">
    <div class="layui-form-item" style="margin:10px;">
        <form>
            <input type="hidden" name="order_id" value="0">


            <div  class="form-group">
                <label > 退款类型</label>
                <input type="checkbox" name="is_freight" value="1" >运费
                <input type="checkbox" name="is_card_fee" value="1" >卡费
                <input type="checkbox" name="is_money" value="1" >订单金额退款
            </div>
            <div  class="form-group">
                <label > 退款原因</label>
                <textarea class="form-control" placeholder="退款原因" name="refund_desc" ></textarea>
            </div>



        </form>
    </div>
</div>

<div id="order_info" style="display: none;" >

        <form class="layui-form ">
            <input type="hidden" name="order_no" value="">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>基本信息</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-block">
                    <span data-name="order_no" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">第三方交易号</label>
                <div class="layui-input-block">
                    <span data-name="third_no" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">回调地址</label>
                <div class="layui-input-block">
                    <span data-name="reply_url" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户</label>
                <div class="layui-input-block">
                    <span data-name="user_name" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">代理</label>
                <div class="layui-input-block">
                    <span data-name="agent_name" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">代理备注</label>
                <div class="layui-input-block">
                    <span data-name="agent_info" style="color:red;font-weight: bold;"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">充值卡号</label>
                <div class="layui-input-block">
                    <span data-name="card_no" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">套餐名称</label>
                <div class="layui-input-block">
                    <span data-name="product_name" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <span data-name="mode" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">付款状态</label>
                <div class="layui-input-block">
                    <span data-name="pay_status" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <span data-name="status" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发货状态</label>
                <div class="layui-input-block">
                    <span data-name="delivery_status" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">IP</label>
                <div class="layui-input-block">
                    <span data-name="ip" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">建单时间</label>
                <div class="layui-input-block">
                    <span data-name="ctime" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">付款时间</label>
                <div class="layui-input-block">
                    <span data-name="pay_time" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">更新时间</label>
                <div class="layui-input-block">
                    <span data-name="mtime" ></span>
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>金额</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">原始价格</label>
                <div class="layui-input-block">
                    <span data-name="basic_price" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <span data-name="money" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">运费</label>
                <div class="layui-input-block">
                    <span data-name="freight" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">卡费</label>
                <div class="layui-input-block">
                    <span data-name="card_fee" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">优惠金额</label>
                <div class="layui-input-block">
                    <span data-name="discount_money" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">总金额</label>
                <div class="layui-input-block">
                    <span data-name="total_money" ></span>
                </div>
            </div>


            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>发货信息</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">收货人</label>
                <div class="layui-input-block">
                    <span data-name="real_name" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-block">
                    <span data-name="mobile" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">收货地址</label>
                <div class="layui-input-block">
                    <span data-name="address" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">快递名称</label>
                <div class="layui-input-block">
                    <span data-name="express_name" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">快递号</label>
                <div class="layui-input-block">
                    <span data-name="express_no" ></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea class="form-control" placeholder="备注" name="order_log_info" ></textarea>
                    <button class="btn btn-primary" type="button" onclick="send_order_log(this)" style="margin:5px;padding:5px;">提交</button>
                </div>
            </div>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>备注信息</legend>
            </fieldset>
            <table class="layui-table">
                <colgroup>
                    <col width="50">
                    <col width="300">
                    <col width="50">
                    <col width="100">
                </colgroup>
                <thead>
                <tr>
                    <th>编号</th>
                    <th>备注</th>
                    <th>操作员</th>
                    <th>时间</th>
                </tr>
                </thead>
                <tbody data-name="order_remark">

                </tbody>
            </table>
        </form>
</div>

{{literal}}
<script id="delivery_list_tmpl" type="text/x-jquery-tmpl">
   <li class="layui-timeline-item">
        <i class="layui-icon layui-timeline-axis"></i>
        <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title">${time}</h3>
            <p>
               ${context}
            </p>
        </div>
    </li>
</script>

{{/literal}}
<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/jquery-migrate-1.2.1.min.js"></script>
<script src="../js/jquery-ui-1.10.3.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery.sparkline.min.js"></script>
<script src="../js/toggles.min.js"></script>
<script src="../js/jquery.cookies.js"></script>
<script src="../js/jquery.tmpl.js"></script>
<script src="../js/custom.js"></script>
<script src="../layui/layui.js"></script>
<script src="../js/jquery.gritter.min.js"></script>
<script src="../js/form.beautify.js?t={{$version}}"></script>
<script src="../js/commen.js?t={{$version}}"></script>
<script src="../js/datatables.js?t={{$version}}"></script>
<link href="../css/ley.dialog.css" rel="stylesheet">
<script src="../js/ley.dialog.js?t={{$version}}"></script>
<script>
    layui.use(['laydate','laypage',"element"], function(){
        var laydate = layui.laydate;
        $("#search_form input[name='date_1']").val(new Date().Format("yyyy-MM-dd"));
        $("#search_form input[name='date_2']").val(new Date().Format("yyyy-MM-dd"));
        laydate.render({
            elem: '#date_1'
        });
        laydate.render({
            elem: '#date_2'
        });

    });
    var admin_id = "{{$ADMIN_ID}}";
    $(function () {


        $("#info_list").datatables({
            idField: 'order_no',
            mobile_field:["ck","order_no","pay_status","status"],
            columns:[
                {field:'ck',checkbox:true },
                {field:'ctime',title:'时间',width:50, formatter: function (value, row, index) {return getLocalTime(value) + "";}},
                {field:'callback_time',title:'结束时间',width:50, formatter: function (value, row, index) {return getLocalTime(value) + "";}},
                {field:'order_id',title:'订单ID',width:40},
                {field:'order_no',title:'订单号',width:50},
                {field:'pay_order_no',title:'支付订单号',width:50},
                {field:'third_no',title:'第三方交易号',width:50},
                {field:'user_mobile',title:'用户账号',width:50},
                {field:'agent_name',title:'卡代理',width:50},
                {field:'card_no',title:'卡号',width:50},
                {field:'card_type',title:'卡类型',width:50,formatter:function (value,row,index) {
                        return get_card_type(value);
                    }},
                {field:'mode',title:'类型',width:30,formatter:function (value,row,index) {
                        return get_mode(value);
                    }},
                {field:'discount_code',title:'卷号',width:50},

                {field:'basic_price',title:'原始价格',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'cost',title:'成本价格',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'money',title:'价格',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'freight',title:'运费',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'card_fee',title:'卡费',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'total_money',title:'总价格',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'supply_basic_price',title:'充值面额',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'supply_cost',title:'充值成本',width:50, formatter: function (value, row, index) {
                    return (value * 0.0001).toFixed(2) + "";}},
                {field:'supply_name',title:'上游',width:50},
                {field:'pay_type',title:'支付方式',width:30,formatter:function (value,row,index) {
                    return pay_type(value);
                }},
                {field:'pay_status',title:'支付状态',width:30,formatter:function (value,row,index) {
                   return get_pay_status(value);
                }},
                {field:'status',title:'状态',width:30,formatter:function (value,row,index) {
                    return get_status(value);
                }},
                {field:'delivery_status',title:'发货状态',width:30,formatter:function (value,row,index) {
                    return get_delivery_status(value);
                }},
                {field:'process_flag',title:'提交状态',width:30,formatter:function (value,row,index) {
                        return get_process_flag(value);
                    }},
                {field:'token_type',title:'来源',width:30,formatter:function (value,row,index) {
                        return get_token_type(value);
                    }},
                {field:'is_rebate',title:'是否返佣',width:30,formatter:function (value,row,index) {
                    if(value === 0)
                    {
                        return "未返";
                    }else{
                        return "已返";
                    }
                }},
                {field:'reply_status',title:'回调状态',width:30,formatter:function (value,row,index) {
                       return get_reply_status(value);
                    }},
                {field:'agent_rebate',title:'代理佣金',width:50, formatter: function (value, row, index) {return (value * 0.0001).toFixed(2) + "";}},
                {field:'operation',title:'操作',width:30,formatter:function (value,row,index) {
                    var text = "";
                    text += '<div class="btn-group"> ';
                    text += '<a data-toggle="dropdown" class="dropdown-toggle"> ';
                    text += '<i class="fa fa-cog"></i> ';
                    text += '</a> ';
                    text += '<ul role="menu" class="dropdown-menu pull-right"> ';
                    text +='<li><a href="javascript:void 0;" onclick="order_info(\''+row.order_id+'\')">订单信息</a></li> ' ;
                    if(row.mode == 1 &&!row.card_no && row.pay_status==1 )
                    {
                        text +='<li><a href="javascript:void 0;" onclick="add_new_card(\''+row.order_id+'\')">添加卡号</a></li> ' ;
                    }

                    if(row.pay_status == 0)
                    {
                        text +='<li><a href="javascript:void 0;" onclick="add_pay(\''+row.order_id+'\')">付款</a></li> ' ;
                        text +='<li><a href="javascript:void 0;" onclick="cancel_pay(\''+row.order_id+'\')">取消订单</a></li> ' ;
                    }else if(row.pay_status == 1){
                        text +='<li><a href="javascript:void 0;" onclick="refund_fee(\''+row.order_id+'\')">退款</a></li> ' ;
                    }
                    if(row.mode == 1 && row.pay_status == 1&& row.status==2)
                    {
                        text +='<li><a href="javascript:void 0;" onclick="delivery(\''+row.order_id+'\')">发货信息</a></li> ' ;
                    }
                    if(row.status == 0 && row.pay_status == 1)
                    {
                        text +='<li><a href="javascript:void 0;" onclick="recharge(\''+row.order_id+'\')">充值</a></li> ' ;
                    }
                    if(row.mode == 0 && row.pay_status == 1 && row.status==2 )
                    {
                        text +='<li><a href="javascript:void 0;" onclick="order_notify_ext(\''+row.order_id+'\')">订单后续处理</a></li> ' ;
                    }
                    if( row.reply_url)
                    {
                        text +='<li><a href="javascript:void 0;" onclick="order_reply(\''+row.order_id+'\')">订单回调</a></li>';
                    }

                    text +='</ul> ';
                    text +='</div>';
                    return text;
                }}

            ],
            ajax:{
                url:"/orders/ajax_order_list",
                parems:get_search_data(),
                callback:function (msg) {
                    check_table_list_data(msg);
                    check_parent_height();
                    var count_cost = "0.00";
                    var count_total_money = "0.00";
                    var count_profit = "0.00";
                    var count_pay_supply_cost = "0.00";
                    var count_supply_cost = "0.00";
                    var count_card_fee = "0.00";
                    var count_agent_rebate = "0.00";
                    if(msg.error == 0 &&msg.money_list)
                    {
                        if(msg.money_list.count_total_money)
                        {
                            count_total_money = (msg.money_list.count_total_money * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_card_fee)
                        {
                            count_card_fee = (msg.money_list.count_card_fee * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_cost)
                        {
                            count_cost = (msg.money_list.count_cost * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_agent_rebate)
                        {
                            count_agent_rebate = (msg.money_list.count_agent_rebate * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_profit)
                        {
                            count_profit = (msg.money_list.count_profit * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_pay_supply_cost)
                        {
                            count_pay_supply_cost = (msg.money_list.count_pay_supply_cost * 0.0001).toFixed(2) + "";
                        }
                        if(msg.money_list.count_supply_cost)
                        {
                            count_supply_cost = (msg.money_list.count_supply_cost * 0.0001).toFixed(2) + "";
                        }
                    }

                    $("#count_total_money").html(count_total_money);
                    $("#count_cost").html(count_cost);
                    $("#count_card_fee").html(count_card_fee);
                    $("#count_agent_rebate").html(count_agent_rebate);
                    $("#count_profit").html(count_profit);
                    $("#count_pay_supply_cost").html(count_pay_supply_cost);
                    $("#count_supply_cost").html(count_supply_cost);
                }
            }

        });
    });
    function send_order_log(obj)
    {
        var obj_form = $(obj).parents("form");
        var order_no = obj_form.find("input[name='order_no']").val();
        var order_log_info = obj_form.find("textarea[name='order_log_info']").val();
        if(order_log_info &&order_no)
        {
            AjaxCommen("GET","/orders/ajax_send_order_log",{order_no:order_no,order_log_info:order_log_info},function (msg) {
                if(msg.error === 0)
                {
                    openMsg("成功");
                    obj_form.find("textarea[name='order_log_info']").val("");
                    if(msg.data["order_log_list"])
                    {
                        var order_log_list = msg.data["order_log_list"];
                        var text = "";
                        for(var i=0;i<order_log_list.length;i++)
                        {
                            var admin_name = "系统";
                            if (order_log_list[i].admin_id !== 0) {
                                admin_name = order_log_list[i].admin_name;

                            }
                            text += '<tr>';
                            text += '<td>';
                            text += order_log_list[i].id;
                            text += '</td>';
                            text += '<td>';
                            text += order_log_list[i].remark;
                            text += '</td>';
                            text += '<td>';
                            text += admin_name;
                            text += '</td>';
                            text += '<td>';
                            text += getLocalTime(order_log_list[i].ctime);
                            text += '</td>';
                            text += '</tr>';
                        }
                        obj_form.find("tbody[data-name='order_remark']").html(text);
                        // console.log(text)
                    }

                }
            });
        }

    }
    function refund_fee(order_id)
    {
        openDialog2({title:"退款信息",area: ['500', "300"],content:$("#refund_fee"),clone:true,before:function (layero) {
                $("input[name='order_id']",layero).val(order_id);
            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;
                $("input[type!='radio'][type!='checkbox'],select,textarea,input[type='radio']:checked,input[type='checkbox']:checked",layero).each(function () {
                    var name = $(this).attr("name");
                    var ignore = $(this).attr("data-ignore");
                    if(name)
                    {
                        var value = $(this).val();
                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            if (ignore != "true")
                            {
                                $(this).parents(".form-group").addClass("has-error");
                                is_false = true;
                            }
                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }

                AjaxCommen("GET","/orders/ajax_refund_fee",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function change_user_id(obj)
    {
        var user_id = $(obj).val();
        var objs = $(obj).parents("form").find("select[name='card_no']");
        // console.log(objs)
        objs.empty();
        AjaxCommen("GET","/orders/ajax_user_card_list",{user_id:user_id},function (msg) {
            if(msg.error === 0)
            {
                var options = "";
                for(var i=0;i<msg.data.length;i++)
                {
                    options += '<option value="'+msg.data[i].card_no+'">'+msg.data[i].card_no+'</option>';
                }
                objs.html(options).trigger("change");

            }
        });
    }
    function add_pay(order_id)
    {
        if(order_id)
        {
            $("body>.dropdown-menu").remove();
            openMsgS("是否付款",function () {
                AjaxCommen("GET","/orders/ajax_add_pay",{order_id:order_id},function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        search();
                    }
                });
            });
        }else{
            openMsg("请选择订单");
        }

    }
    function cancel_pay(order_id)
    {
        if(order_id)
        {
            $("body>.dropdown-menu").remove();
            openMsgS("是否取消",function () {
                AjaxCommen("GET","/orders/ajax_cancel_pay",{order_id:order_id},function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        search();
                    }
                });
            });
        }else{
            openMsg("请选择订单");
        }

    }
    function add_new_card(order_id)
    {
        $("#add_new_card form")[0].reset();
        $("body>.dropdown-menu").remove();
        openDialog2({title:"开卡信息",area: ['500', "300"],content:$("#add_new_card"),clone:true,before:function (layero) {
            $("input[name='order_id']",layero).val(order_id);
            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;
                $("input[type!='radio'],select,textarea,input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");
                    var ignore = $(this).attr("data-ignore");
                    if(name)
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            if (ignore != "true")
                            {
                                $(this).parents(".form-group").addClass("has-error");
                                is_false = true;
                            }
                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }

                AjaxCommen("GET","/orders/ajax_add_new_card",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function add_card()
    {
        $("#add_card form")[0].reset();
        openDialog2({title:"开卡信息",area: ['500', "600"],content:$("#add_card"),clone:true,before:function (layero) {
            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;
                $("#add_card input[type!='radio'],#add_card select,#add_card textarea,#add_card input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");
                    var ignore = $(this).attr("data-ignore");
                    if(name)
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            if (ignore != "true")
                            {
                                $(this).parents(".form-group").addClass("has-error");
                                is_false = true;
                            }

                        }


                    }
                });
                if(is_false)
                {
                    return false;
                }

                AjaxCommen("GET","/orders/ajax_add_card",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");
                        layero.close();
                        search();
                    }
                });
            }
        });
    }
    function add_recharge()
    {
        $("#add_recharge form")[0].reset();
        openDialog2({title:"充值信息",area: ['500', "400"],content:$("#add_recharge"),clone:true,before:function (layero) {
            },
            yes:function (index,layero) {
                var data = {};
                var is_false = false;
                $("input[type!='radio'], select,textarea,input[type='radio']:checked",layero).each(function () {
                    var name = $(this).attr("name");
                    var ignore = $(this).attr("data-ignore");
                    if(name)
                    {
                        var value = $(this).val();

                        if(value)
                        {
                            data[name] = value;
                            $(this).parents(".form-group").removeClass("has-error");
                        }else{
                            if (ignore != "true")
                            {
                                $(this).parents(".form-group").addClass("has-error");
                                is_false = true;
                            }
                        }
                    }
                });
                if(is_false)
                {
                    return false;
                }

                AjaxCommen("GET","/orders/ajax_add_recharge",data,function (msg) {
                    if(msg.error === 0)
                    {
                        openMsg("成功");

                        search();
                        layero.close();
                    }
                });
            }
        });
    }
    function order_info(order_id)
    {
        $("#order_info form")[0].reset();
        if(order_id)
        {
            $("body>.dropdown-menu").remove();
            AjaxCommen("GET","/orders/ajax_order_info",{order_id:order_id},function (msg) {
                if(msg.error === 0)
                {
                    var order_no = msg.data.order_no;

                    openDialog2({title:"订单信息",area: ['800', "600"],content:$("#order_info"),clone:true,btn:[],before:function (layero) {
                            $("input[name='order_no']",layero).val(order_no);
                            $("span",layero).each(function () {
                                var name = $(this).attr("data-name");
                                if(name)
                                {
                                    var value = msg.data[name];
                                    if(name == "mode")
                                    {
                                        value = get_mode(value);
                                    }
                                    if(name == "pay_type")
                                    {
                                        value = get_pay_type(value);
                                    }
                                    if(name == "pay_status")
                                    {
                                        value = get_pay_status(value);
                                    }
                                    if(name == "status")
                                    {
                                        value = get_status(value);
                                    }
                                    if(name == "delivery_status")
                                    {
                                        value = get_delivery_status(value);
                                    }
                                    if(in_array(name,["basic_price","cost","money","freight","card_fee","discount_money","total_money"]))
                                    {

                                        value = (value * 0.0001).toFixed(2)+"";
                                    }
                                    if(in_array(name,["pay_time","ctime","mtime"]))
                                    {

                                        value = getLocalTime(value);
                                    }
                                    if(value != undefined)
                                    {
                                        $(this).html(value);
                                    }else{
                                        $(this).html("&nbsp;");
                                    }
                                }
                            });
                            if(msg.data["order_log_list"])
                            {
                                var order_log_list = msg.data["order_log_list"];
                                var text = "";
                                for(var i=0;i<order_log_list.length;i++)
                                {
                                    var admin_name = "系统";
                                    if (order_log_list[i].admin_id != 0) {
                                        admin_name = order_log_list[i].admin_name;

                                    }
                                    text += '<tr>';
                                    text += '<td>';
                                    text += order_log_list[i].id;
                                    text += '</td>';
                                    text += '<td>';
                                    text += order_log_list[i].remark;
                                    text += '</td>';
                                    text += '<td>';
                                    text += admin_name;
                                    text += '</td>';
                                    text += '<td>';
                                    text += getLocalTime(order_log_list[i].ctime);
                                    text += '</td>';
                                    text += '</tr>';
                                }
                                layero.find("tbody[data-name='order_remark']").html(text);
                                // console.log(text)
                            }
                        }
                    });
                }
            });
        }
    }
    function delivery(order_id) {
        $("#delivery form")[0].reset();
        if(order_id)
        {
            $("body>.dropdown-menu").remove();
            AjaxCommen("GET","/orders/ajax_order_info",{order_id:order_id,is_delivery:1},function (msg) {
                if(msg.error === 0)
                {

                    openDialog2({title:"开卡信息",area: ['500', "600"], btn: ['确定','取消','发货短信'],content:$("#delivery"),clone:true,before:function (layero) {
                            layero.find("input[name='agent_name']").val(msg.data["agent_name"]);
                            layero.find("input[name='agent_info']").val(msg.data["agent_info"]);
                            layero.find("input[name='order_id']").val(msg.data["order_id"]);
                            layero.find("input[name='real_name']").val(msg.data["real_name"]);
                            layero.find("input[name='mobile']").val(msg.data["mobile"]);
                            layero.find("textarea[name='address']").val(msg.data["address"]);
                            layero.find("input[name='express_name']").val(msg.data["express_name"]);
                            layero.find("input[name='express_no']").val(msg.data["express_no"]);
                            layero.find("select[name='delivery_status']").val(msg.data["delivery_status"]).trigger("change");
                            if(msg.data["corp_code"] == "shunfeng" &&msg.data["express_no"])
                            {
                                layero.find("#express_no_text").html('<a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/'+msg.data["express_no"]+'">官网</a>')
                            }
                            $("#delivery_list",layero).empty();
                            if(msg.data.delivery_list)
                            {
                                var delivery_list = msg.data.delivery_list;
                                // console.log(delivery_list);

                                // var state = delivery_list.state;
                                if(delivery_list.status != "200")
                                {
                                    $("#delivery_list_state",layero).html("没有数据");
                                    var delivery_list_info = $("#delivery_list_tmpl").tmpl({time:new Date().Format("yyyy-MM-dd"),context:delivery_list.data});
                                    $("#delivery_list",layero).append(delivery_list_info);

                                }else{
                                    // delivery_list.data.reverse();
                                    var delivery_list_info = $("#delivery_list_tmpl").tmpl(delivery_list.data);
                                    $("#delivery_list",layero).append(delivery_list_info);
                                    $("#delivery_list_state",layero).html("发货中");
                                }

                            }else{
                                $("#delivery_list_state",layero).html("没有数据");
                            }

                        },
                        yes:function (index,layero) {
                            var data = {};
                            var is_false = false;
                            $("input[type!='radio'],select,textarea,input[type='radio']:checked",layero).each(function () {
                                var name = $(this).attr("name");
                                var ignore = $(this).attr("data-ignore");
                                if(name)
                                {
                                    var value = $(this).val();
                                    if(value)
                                    {
                                        data[name] = value;
                                        $(this).parents(".form-group").removeClass("has-error");
                                    }else{
                                        if (ignore != "true")
                                        {
                                            $(this).parents(".form-group").addClass("has-error");
                                            is_false = true;
                                        }
                                    }
                                }
                            });
                            if(is_false)
                            {
                                return false;
                            }

                            AjaxCommen("GET","/orders/ajax_set_delivery",data,function (msg) {
                                if(msg.error === 0)
                                {
                                    openMsg("成功");
                                    layero.close();
                                    search();
                                }
                            });
                        },
                        btn3:function (index,layero,e) {
                            promptMsg("确认发送发货短信？",function () {
                                var express_name = layero.find("input[name='express_name']").val();
                                var express_no = layero.find("input[name='express_no']").val();
                                AjaxCommen("GET","/orders/ajax_send_delivery_msg",{order_id:order_id,express_name:express_name,express_no:express_no},function (msg) {
                                    if(msg.error === 0)
                                    {
                                        openMsg("发送成功");

                                    }
                                });
                            });

                        }
                    });
                }
            });
        }
    }
    function recharge(order_id)
    {
        promptMsg("确认充值？",function () {
            AjaxCommen("GET","/orders/ajax_recharge",{order_id:order_id},function (msg) {
                if(msg.error === 0)
                {
                    openMsg("成功");

                }
                search();
            });
        });

    }
    function order_notify_ext(order_id)
    {
        promptMsg("确认订单扩展处理？",function () {
            AjaxCommen("GET","/orders/ajax_order_notify_ext",{order_id:order_id},function (msg) {
                if(msg.error === 0)
                {
                    openMsg("成功");

                }
                search();
            });
        });
    }
    function order_reply(order_id)
    {
        promptMsg("确认订单回调？",function () {
            AjaxCommen("GET","/orders/ajax_order_reply",{order_id:order_id},function (msg) {
                if(msg.error === 0)
                {
                    openMsg("成功");

                }
                search();
            });
        });
    }
    function export_csv()
    {

        var data = get_search_data();
        AjaxCommen("GET","/orders/ajax_export_order_list",data,function (msg) {
            if(msg.error === 0)
            {
                var filename = msg.data.filename;
                location.href = filename;
            }
        });

        // var aLink = $("#test")[0];
        // var str = "栏位1,栏位2,栏位3\n值1,值2,值3";
        // str =  encodeURIComponent(str);
        // aLink.href = "data:text/csv;charset=utf-8,\ufeff"+str;
        // aLink.click();
    }
    function search()
    {
        var data = get_search_data();

        $("#info_list").setParems(data);
        $("#info_list").reload();

    }
    function search_reset() {
        $("#search_form")[0].reset();
        search();
    }
    function get_search_data() {
        var data = {};
        $('#search_form select,#search_form input').each(function () {
            var name = $(this).attr("name");
            if(name)
            {
                data[name] = $(this).val();
            }

        });
        return data;
    }
</script>

</body>
</html>
